package com.reden.utils;

import java.util.Collection;
import java.util.Map;

public class ValidateUtil {

    // 空值
    public static boolean isNull(Object object) {return object == null;}
    public static boolean isNotNull(Object object) {return !isNull(object);}

    // 空量
    public static boolean isEmpty(Object object) {return object == null || object == "";}
    public static boolean isNotEmpty(Object object) {return !isEmpty(object);}
    public static boolean isEmpty(Object[] objects) {return objects == null || objects.length == 0;}
    public static boolean isNotEmpty(Object[] objects) {return !isEmpty(objects);}
    public static boolean isEmpty(Collection<?> objects) {return objects == null || objects.size() == 0;}
    public static boolean isNotEmpty(Collection<?> objects) {return !isEmpty(objects);}
    public static boolean isEmpty(Map<?, ?> object) { return isNull(object) || object.isEmpty(); }
    public static boolean isNotEmpty(Map<?, ?> object) { return !isEmpty(object); }

    // 空串
    public static boolean isBlank(String string) {return string == null || string.trim() == "";}
    public static boolean isNotBlank(String string) {return !isBlank(string);}

    // 整数
    public static boolean isInteger(String string) {return isNotNull(string) && string.matches("^-?\\d+$");}
    public static boolean isNotInteger(String string) {return !isInteger(string);}

    // 小数
    public static boolean isDecimal(String string) {return isNotNull(string) && string.matches("^-?\\d+\\.\\d+$");}
    public static boolean isNotDecimal(String string) {return !isDecimal(string);}

    // 数字
    public static boolean isNumber(String string) {return isInteger(string) || isDecimal(string);}
    public static boolean isNotNumber(String string) {return !isNumber(string);}

    // 邮箱
    public static boolean isEmail(String string) {return isNotNull(string) && string.matches("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");}
    public static boolean isNotEmail(String string) { return !isEmail(string); }
    
    // 手机
    public static boolean isMobile(String string) {return isNotNull(string) && string.matches("^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\\d{8}$");}
    public static boolean isNotMobile(String string) { return !isMobile(string); }
    
    // 身份证
    public static boolean isIdentity(String string) {return isNotNull(string) && string.matches("(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)");}
    public static boolean isNotIdentity(String string) { return !isIdentity(string); }
}
